package com.inforich.disposal.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.Arrays;
import cn.hutool.core.bean.BeanUtil;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestParam;
import com.inforich.common.annotation.Log;
import com.inforich.common.core.controller.BaseController;
import com.inforich.common.core.domain.AjaxResult;
import com.inforich.common.enums.BusinessType;
import com.inforich.disposal.domain.DisposalLandTerminalVehicleApproach;
import com.inforich.disposal.service.IDisposalLandTerminalVehicleApproachService;
import com.inforich.common.utils.poi.ExcelUtil;

/**
 * 处置终端车辆进场明细Controller
 *
 * @author hjm
 * @date 2022-10-25
 */
@RestController
@RequestMapping("/disposal/approach")
public class DisposalLandTerminalVehicleApproachController extends BaseController {

  @Autowired
  private IDisposalLandTerminalVehicleApproachService disposalLandTerminalVehicleApproachService;

  /**
   * 查询处置终端车辆进场明细列表
   */
  @PreAuthorize("@ss.hasPermi('disposal:approach:list')")
  @GetMapping("/list")
  public Page<DisposalLandTerminalVehicleApproach> list(
      Page<DisposalLandTerminalVehicleApproach> page,
      DisposalLandTerminalVehicleApproach disposalLandTerminalVehicleApproach) {
    Map<String, Object> map = beanToMap(disposalLandTerminalVehicleApproach);
    disposalLandTerminalVehicleApproachService.pageDisposalLandTerminalVehicleApproach(page, map);
    return page;
  }


  /**
   * 导出处置终端车辆进场明细列表
   */
  @PreAuthorize("@ss.hasPermi('disposal:approach:export')")
  @Log(title = "处置终端车辆进场明细", businessType = BusinessType.EXPORT)
  @PostMapping("/export")
  public void export(HttpServletResponse response,
      DisposalLandTerminalVehicleApproach disposalLandTerminalVehicleApproach) {
    Map<String, Object> map = beanToMap(disposalLandTerminalVehicleApproach);
    List<DisposalLandTerminalVehicleApproach> list = disposalLandTerminalVehicleApproachService.listDisposalLandTerminalVehicleApproach(
        map);
    ExcelUtil<DisposalLandTerminalVehicleApproach> util = new ExcelUtil<DisposalLandTerminalVehicleApproach>(
        DisposalLandTerminalVehicleApproach.class);
    util.exportExcel(response, list, "处置终端车辆进场明细数据");
  }

  /**
   * 获取处置终端车辆进场明细详细信息
   */
  @PreAuthorize("@ss.hasPermi('disposal:approach:query')")
  @GetMapping(value = "/{id}")
  public AjaxResult getInfo(@PathVariable("id") Long id) {
    return AjaxResult.success(disposalLandTerminalVehicleApproachService.getById(id));
  }

  /**
   * 新增处置终端车辆进场明细
   */
  @PreAuthorize("@ss.hasPermi('disposal:approach:add')")
  @Log(title = "处置终端车辆进场明细", businessType = BusinessType.INSERT)
  @PostMapping
  public AjaxResult add(
      @Validated @RequestBody DisposalLandTerminalVehicleApproach disposalLandTerminalVehicleApproach) {
    return toAjax(
        disposalLandTerminalVehicleApproachService.save(disposalLandTerminalVehicleApproach));
  }

  /**
   * 修改处置终端车辆进场明细
   */
  @PreAuthorize("@ss.hasPermi('disposal:approach:edit')")
  @Log(title = "处置终端车辆进场明细", businessType = BusinessType.UPDATE)
  @PutMapping
  public AjaxResult edit(
      @Validated @RequestBody DisposalLandTerminalVehicleApproach disposalLandTerminalVehicleApproach) {
    return toAjax(
        disposalLandTerminalVehicleApproachService.updateById(disposalLandTerminalVehicleApproach));
  }

  /**
   * 删除处置终端车辆进场明细
   */
  @PreAuthorize("@ss.hasPermi('disposal:approach:remove')")
  @Log(title = "处置终端车辆进场明细", businessType = BusinessType.DELETE)
  @DeleteMapping("/{ids}")
  public AjaxResult remove(@PathVariable Long[] ids) {
    return toAjax(disposalLandTerminalVehicleApproachService.removeByIds(Arrays.asList(ids)));
  }
}
